<template>
  <el-table :data="items" border stripe style="width: 100%">
    <div>视频列表</div>
    <el-table-column prop="_id" label="_id" width="200"> </el-table-column>
    <el-table-column prop="parent.name" label="上级分类" width="200">
    </el-table-column>
    <el-table-column prop="videoname" label="视频名称" width="200">
    </el-table-column>
    <el-table-column prop="video" label="视频图标" width="200">
      <template slot-scope="scope">
        <video class="icon" :src="scope.row.video" alt=""></video>
      </template>
    </el-table-column>
    <el-table-column fixed="right" label="操作" width="300">
      <template slot-scope="scope">
        <el-button
          type="primary"
          size="small"
          @click="$router.push(`/shipin/create/${scope.row._id}`)"
          >编辑</el-button
        >
        <el-button @click="handleClick(scope.row)" type="primary" size="small"
          >删除</el-button
        >
      </template>
    </el-table-column>
  </el-table>
</template>
<script>
export default {
  data() {
    return {
      items: []
    };
  },
  methods: {
    handleClick(row) {
      this.$confirm(`此操作将永久删除${row.name}, 是否继续?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true
      })
        .then(() => {
          this.$http.delete(`/rest/video/${row._id}`).then(() => {
            this.$http.get("/rest/video").then(res => {
              this.items = res.data;
            });
          });
          this.$message({
            type: "success",
            message: "删除成功!"
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    fetch() {
      this.$http.get("/rest/videos").then(res => {
        this.items = res.data;
      });
    }
  },
  created() {
    this.fetch();
  }
};
</script>
<style>
.icon {
  width: 50px;
  height: 50px;
}
</style>
